﻿//ajax
function update_attention(labelname) {
  ReturnURL="/attention/label/"
  htmlobj=$.ajax({
  	type:'POST',
  	url:ReturnURL,
  	cache:false,
  	async:false,
  	data:"labelname="+labelname
  	});
  $("#div_attention").html(htmlobj.responseText);
}

//标题搜索
function update_attention_search() {
  ReturnURL="/attention/search/"
  searchinfo=document.getElementById("id_search").value
  htmlobj=$.ajax({
  	type:'POST',
  	url:ReturnURL,
  	cache:false,
  	async:false,
  	data:"searchinfo="+searchinfo
  	});
  $("#div_attention").html(htmlobj.responseText);
}

//没用
function myPosition(){
	var mySel=document.getElementById("id_sel");
	var myLabel=document.getElementById("id_label");
	//设置宽和高
	mySel.style.height=myLabel.offsetHeight+'px';
	mySel.style.width=(myLabel.offsetWidth+20)+'px';
	//设置左绝对位置
	myLabel=document.getElementById("id_label");
	myLabel_left=myLabel.offsetLeft;
	while(myLabel.offsetParent!=null){
		myLabel_left += myLabel.offsetParent.offsetLeft;
		myLabel = myLabel.offsetParent;
	}
	mySel.style.left=myLabel_left+'px';
	//设置上绝对位置
	myLabel=document.getElementById("id_label");
	myLabel_top=myLabel.offsetTop;
	while(myLabel.offsetParent!=null){
		myLabel_top += myLabel.offsetParent.offsetTop;
		myLabel = myLabel.offsetParent;
	}
	mySel.style.top=myLabel_top+'px';
	//设置层叠
	//document.getElementById("id_label").style.zIndex=-1;
}

//关闭窗口
function winclose(){
	window.opener.location.reload();
	//window.opener=null;
	//window.open('','_self','');
	//window.close();
}

//弹出层
function OpenWin(idx)
{
	var oLay = document.getElementById("overlay");	
	var oWin = document.getElementById("win");
	oLay.style.display = "block";
	oLay.style.width=document.body.clientWidth;
	oLay.style.height=document.body.clientHeight;
	oWin.style.display = "block";
	document.getElementById("wintmp").innerHTML=idx
};

function CloseWin()
{
	var oLay = document.getElementById("overlay");	
	var oWin = document.getElementById("win");
	oLay.style.display = "none";
	oWin.style.display = "none"
};

function ReturnParent()
{
	var idx=document.getElementById("wintmp").innerHTML;
	parent.location="/attention/del/?idx="+idx
}

//翻页
var record = 15;//每页显示多少条记录
var count = 1;//记录总数
var pageTotal = 1//总页数
var pagenum = 1;//将要显示的页码

//重新整理当前页码，如果页面小于1，则赋值为1，如果大于总页数，则等于总页数
coordinatePagenum(pagenum);

//根据当前要显示的页码取得当前面里第一条记录的号码
var pageBegin = (record*(pagenum-1)+1)|0;

//根据当前要显示的页码取得当前面里最后一条记录的号码
var pageEnd = record*pagenum;

function initdata(pagenum)
{
var list_obj = document.getElementById("id_myTable").getElementsByTagName("tr");
count=list_obj.length; 
pageTotal = ((count+record-1)/record)|0;//总页数
totalNum.innerHTML=pageTotal;  
makeSelect(pageTotal)
showhiddenRecord(pagenum)
}
function showhiddenRecord(pagenum){
  number.innerHTML=pagenum;
  if(pagenum<=1){
  theFirstPage.innerHTML="第一页";
  thePrePage.innerHTML="上一页";
  }else{
  theFirstPage.innerHTML="<a href=\"javascript:firstPage()\">第一页</a>";
  thePrePage.innerHTML="<a href=\"javascript:prePage()\">上一页</a>";
  }
  if(pagenum>=pageTotal){
  theNextPage.innerHTML="下一页";
  theLastPage.innerHTML="最后一页";
  }else{
  theNextPage.innerHTML="<a href=\"javascript:nextPage()\">下一页</a>";
  theLastPage.innerHTML="<a href=\"javascript:lastPage()\">最后一页</a>";
  }
  document.getElementById('goto').value=pagenum;
  //根据当前要显示的页码取得当前面里第一条记录的号码
  pageBegin = (record*(pagenum-1)+1)|0;

  //根据当前要显示的页码取得当前面里最后一条记录的号码
  pageEnd = record*pagenum;
  list_obj = document.getElementById("id_myTable").getElementsByTagName("tr");
  for(var i=0;i<list_obj.length;i++){
    if(i>=pageBegin-1 && i<=pageEnd-1){
      list_obj[i].style.display="";
    }else{
    list_obj[i].style.display="none";
    }
  }
}

function firstPage(){
pagenum=1;
showhiddenRecord(pagenum);
}

function lastPage(){
pagenum=pageTotal
showhiddenRecord(pageTotal);
}

//重新整理当前页码，如果页面小于1，则赋值为1，如果大于总页数，则等于总页数
function coordinatePagenum(num){
if(num<1){
num="1";
}else if(num>pageTotal){
num=pageTotal;
}
}

function prePage(){
pagenum--;
coordinatePagenum(pagenum);
showhiddenRecord(pagenum);
}

function nextPage(){
pagenum++;
coordinatePagenum(pagenum);
showhiddenRecord(pagenum);
}

function gotoPage(num){
pagenum=num
coordinatePagenum(pagenum);
showhiddenRecord(num);
}

function makeSelect(pageTotal)
{
var selectObj = document.getElementById('mySelect');
selectObj.options.length = 0;
for(var i=1;i<=pageTotal;i++)
{
   selectObj.options.add(new Option(i,i));    
}
}